<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
	+ request.getServerName() + ":" + request.getServerPort()
	+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Mua~亲亲宠————新增宠物类别</title>
<link rel="stylesheet" href="css/style.css" />

<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" href="css/bootstrapValidator.css" />

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>

</head>
<body>
	<%@ include file="/WEB-INF/jsp/mgnt/mgntTop.jspf"%>
	<div class="title"></div>
	<div class="container  col-sm-offset-2  col-sm-8">
		<div class="panel panel-info">
			<div class="panel-heading">
				<h3 class="panel-title">新增宠物品种</h3>
			</div>
			<div class="panel-body">
				<div class="col-sm-offset-1  col-sm-9 column">
					<form id="varietyForm" class="form-horizontal">
						<div class="form-group">
							<label class="col-sm-3 control-label">名称：</label>
							<div class="col-sm-9">
								<input type="text" name="varietyName" class="form-control" />
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">类别：</label>
							<div class="col-sm-9">
								<label class="radio-inline"> <input type="radio"
									name="type" value="1" checked> 猫</label> <label
									class="radio-inline"> <input type="radio" name="type"
									value="2"> 狗</label>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">详细描述：</label>
							<div class="col-sm-9">
								<div class="textarea">
									<textarea class="form-control" rows="5" name="description">${editingPet.description}</textarea>
								</div>
							</div>
						</div>
						<div class="col-sm-offset-2 col-sm-8">
							<button type="button" class="btn btn-info col-sm-offset-2"
								onclick="checkAndSubmit()">确认</button>
							<button onclick="javascript:history.go(-1);"
								class="btn btn-info col-sm-offset-2 ">取消</button>
						</div>
					</form>

				</div>
			</div>
		</div>
	</div>

	<script>
		$(document).ready(function() {
			$('#varietyForm').bootstrapValidator({
				message : 'This value is not valid',
				excluded : [ ':disabled' ],
				feedbackIcons : {
					valid : 'glyphicon glyphicon-ok',
					invalid : 'glyphicon glyphicon-remove',
					validating : 'glyphicon glyphicon-refresh'
				},
				fields : {
					varietyName : {
						message : '',
						validators : {
							notEmpty : {
								message : '名称不能为空'
							},
							stringLength : {
								min : 2,
								max : 50,
								message : '名称最少2个字，最多50字'
							}
						}
					},
					type : {
						message : '',
						validators : {
							notEmpty : {
								message : '类别必选'
							}
						}
					}
				}
			});
		});
		function checkAndSubmit() {
			$("#varietyForm").bootstrapValidator('validate');//提交验证  
			if ($("#varietyForm").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码  
				$.ajax({
					url : "manage/addVariety.do",
					data : $("#varietyForm").serialize(),
					type : "POST",
					success : function(result) {
						//请求成功时
						if (result.msg == 'success') {

							$(".modal-body").html("新增品种成功，点击确定前往品种列表");

							$("#topModal").modal("show");
							$("#topModal").on('hidden.bs.modal', function() {
								var gotoURL = "manage/varietyMgnt.do";
								window.location.href = gotoURL;
							});
						} else if (result.msg == 'error') {
							$(".modal-body").html(result.errorMsg);
							$("#topModal").modal("show");
						}
					},
					error : function() {
						//请求失败时
						$(".modal-body").html("提交品种失败");
						$("#topModal").modal("show");
					}

				});
			}
		}
	</script>


</body>
</html>

